using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace OraHRDAO
{
	///<summary>
	/// DAO Class for the REGIONS table.
	///</summary>
	public class REGIONS : Entity
	{
		private Int32 _REGION_ID;
		private String _REGION_NAME;
	
		///Default constructor
		public REGIONS ()
		{
		
		}

        /// <summary>
        /// Constructor for joins. 
		/// Available CHILD tables to join with:
		///    - COUNTRIES ( COUNTRIES_COUNTR_REG_FK )
        /// </summary>
        public REGIONS(bool Flat, params Entity[] entities)
            : this()
		{
			foreach(Entity entity in entities)
			{
				string[] entityParts = entity.GetType().ToString().Split('.');
				string entityName = entityParts[entityParts.Length - 1];
				PropertyInfo pf = GetType().GetProperty((entityName));
				if (pf != null)
				{
					pf.SetValue(this,new EntityCollection(entity), null);
				}
                entityName = entityName + "_";
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
			}
			SetFlat(Flat);
		}

		///Constructor for Joins with flat hierarchy
        public REGIONS(params Entity[] entities)
            : this(true, entities)
		{
		}
	
		///<summary>
		/// Property for column REGION_ID.
		///</summary>
		[IsNotNullable]
		[IsPK]
		public Int32 REGION_ID
		{
			get
			{
				return _REGION_ID;
			}
			set
			{
				_REGION_ID = value;
			}
		}
		///<summary>
		/// Property for column REGION_NAME.
		///</summary>
		[MaxLength(25)]
		public String REGION_NAME
		{
			get
			{
				return _REGION_NAME;
			}
			set
			{
				_REGION_NAME = value;
			}
		}
	
        #region COUNTRIES 
        private EntityCollection _COUNTRIES;
		///<summary>
		/// Related table COUNTRIES as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(COUNTRIES),"COUNTRIES")]
        public EntityCollection COUNTRIES
        {
            get
            {
                return _COUNTRIES;
            }

            set
            {
                _COUNTRIES = value;
            }
        }
        private COUNTRIES _COUNTRIES_;
		///<summary>
		/// Related table COUNTRIES as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public COUNTRIES COUNTRIES_
        {
            get
            {
                return _COUNTRIES_;
            }

            set
            {
                _COUNTRIES_ = value;
            }
        }
        #endregion
	    /// <summary>
	    /// Gets join for current entity and table.
	    /// </summary>
	    /// <param name="tableName">Table to join with entity.</param>
	    /// <returns>Join definition for entity and table.</returns>
        public override DBJoin GetJoin(string tableName)
        {
			if (string.Compare(tableName, "COUNTRIES", StringComparison.OrdinalIgnoreCase) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".REGION_ID");
				right.Add(GetType().Name + ".REGION_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			return null;
		}
	}
}


